﻿
using Maticsoft.BLL;
using Maticsoft.Model;

using System;
using System.Collections.Specialized;
using System.Web.UI.HtmlControls;
using Utils;

public partial class WebPage_User_Bianji : SystemBBasePage
{
    protected NameValueCollection curUser = new NameValueCollection();


    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        this.HeaderControl1.Select = "user";
        if (!base.IsPostBack)
        {
            if (base.Request.QueryString["id"] != null)
            {
                if (base.Request.QueryString["id"].ToString() != "")
                {
                    this.ID = Convert.ToInt32(base.Request.QueryString["id"].ToString());
                }
                else
                {
                    this.ID = -1;
                }
            }
            else
            {
                base.Response.Redirect("Users.aspx", true);
            }
            if (this.ID > -1)
            {
                this.selectUser();
            }
        }
    }

    private void selectUser()
    {
        Maticsoft.BLL.UserInfo info = new Maticsoft.BLL.UserInfo();
        Maticsoft.Model.UserInfo info2 = new Maticsoft.Model.UserInfo();
        foreach (Maticsoft.Model.UserInfo info3 in info.GetModelList("id=" + this.ID))
        {
            this.curUser = Helper.GetObjectProtery(info3);
            this.email.Value = info3.Email;
            this.username.Value = info3.Username;
            this.realname.Value = info3.Realname;
            this.qq.Value = info3.Qq;
            this.zipcode.Value = info3.Zipcode;
            this.address.Value = info3.Address;
            this.mobile.Value = info3.Mobile;
            this.secret.Value = info3.Secret;
            this.manager.Value = info3.Manager;
        }
    }

    protected void submit_ServerClick(object sender, EventArgs e)
    {
        this.updateUser();
    }

    private void updateUser()
    {
        Maticsoft.BLL.UserInfo info = new Maticsoft.BLL.UserInfo();
        Maticsoft.Model.UserInfo model = new Maticsoft.Model.UserInfo();
        model = info.GetModel(this.ID);
        model.Email = this.email.Value;
        model.Username = this.username.Value;
        model.Realname = this.realname.Value;
        model.Qq = this.qq.Value;
        if (this.password.Value != string.Empty)
        {
            model.Password = PassWord.MD5(this.password.Value);
        }
        model.Zipcode = this.zipcode.Value;
        model.Address = this.address.Value;
        model.Mobile = this.mobile.Value;
        model.Secret = this.secret.Value;
        model.Manager = this.manager.Value;
        info.Update(model);
        base.SetSuccess("修改用户信息成功");
        base.Response.Redirect(base.Request.Url.AbsoluteUri);
        base.Response.End();
    }

    protected void zipcode_ServerChange(object sender, EventArgs e)
    {
    }

    private int ID
    {
        get
        {
            return Convert.ToInt32(this.ViewState["_ID"].ToString());
        }
        set
        {
            this.ViewState["_ID"] = value;
        }
    }
}

